package com.hualan.zhsq.service.impl.car;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hualan.zhsq.entity.car.Region;
import com.hualan.zhsq.mapper.car.RegionMapper;
import com.hualan.zhsq.service.car.RegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName RegionServiceImpl
 * @Description 区域管理serviceImpl
 * @Author ZheRan
 * @Date 2025年08月03日 下午4:55
 * @Version 1.0
 */
@Service("regionService")
public class RegionServiceImpl implements RegionService {
    @Autowired
    private RegionMapper regionMapper;

    @Override
    public int add(Region entity) {
        return regionMapper.insert(entity);
    }

    @Override
    public int edit(Region entity) {
        return regionMapper.updateById(entity);
    }

    @Override
    public int remove(Integer id) {
        return regionMapper.deleteById(id);
    }

    @Override
    public int removeBatch(Integer[] ids) {
        return regionMapper.deleteBatchIds(List.of(ids));
    }

    @Override
    public List<Region> find() {
        return regionMapper.selectList(null);
    }

    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, Region entity) {
        Page<Region> page = new Page<>(pageNum, pageSize);
        Page<Region> regionPage = regionMapper.selectPage(page, null);
        Map<String, Object> map = new HashMap<>();
        map.put("list",regionPage.getRecords());
        map.put("total", regionPage.getTotal());
        map.put("size", regionPage.getSize());
        return map;
    }

    @Override
    public Region findById(Integer id) {
        return regionMapper.selectById(id);
    }
}
